
using System;
using Microsoft.Practices.Prism.Events;
using NUnit.Framework;

namespace Chambills.Present.AutoMockingEventAggregator.Tests
{
    [TestFixture]
    public class AutoMockingEventAggregatorTestCase
    {
        private AutoMockingEventAggregator events;

        [SetUp]
        public void Setup()
        {
            events = new AutoMockingEventAggregator();
        }

        [Test]
        public void ShouldNotFailIfSubscribedOnUIThread()
        {
            var theEvent = events.GetEvent<AnEvent>();

            theEvent.Subscribe(Console.WriteLine, ThreadOption.UIThread);
            theEvent.Publish("Success");

            theEvent.AssertSubscriptionWasOnUiThread("Success");

        }


        [Test]
        public void ShouldNotifySubscribersWhenEventPublished()
        {
            var theEvent = events.GetEvent<AnEvent>();
            string result = null;
            theEvent.Subscribe(s => result = s);
            theEvent.Publish("Success");
            Assert.AreEqual("Success", result);
        }


        [Test]
        public void ShouldNotFailWhenGetEventCalled()
        {
           events.GetEvent<AnEvent>();
        }

        public class AnEvent : CompositePresentationEvent<string>{}
    }
}
